package com.briup.web.controller;

import com.briup.util.Result;
import com.briup.util.ResultCode;
import com.briup.util.UploadUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @BelongsProject: cms
 * @BelongsPackage: com.briup.web.controller
 * @Author: li
 * @CreateTime: 2024-11-21  09:10
 * @Description: TODO
 * @Version: 1.0
 */
@Api(tags = "文件上传模块")
@Slf4j
@RestController
@RequestMapping("/auth")
public class UploadController {
    @Autowired
    UploadUtil uploadUtil;

    @PostMapping("upload")
    public Result upload(@RequestPart MultipartFile img){
        try {
            String url = uploadUtil.fileToOSS(img);
            return Result.success(url);
        } catch (Exception e) {
            log.error("图片上传失败");
            return Result.failure(ResultCode.INTERFACE_REQUEST_TIMEOUT);
        }
    }
}
